package com.nz2004.service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.nz2004.dao.UserDao;
import com.nz2004.entity.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional
public class UserServiceImpl implements com.nz2004.service.UserService {
    @Autowired
    private UserDao userDao;
    @Override
    @Transactional(propagation = Propagation.SUPPORTS)
    public PageInfo<User> queryUser(Integer currentPage , Integer pageNum) {
        PageHelper.startPage(currentPage,pageNum);
        List<User> users = userDao.queryUserById();
        return new PageInfo<User>(users);
    }

    @Override
    @Transactional
    public Integer insertUser(User user) {
        return userDao.insertUser(user);
    }

    @Override
    public User selectId(Integer id) {
        User user = userDao.selectId(id);
        if(user != null){
            return user;
        }
        return null;
    }

    @Override
    public Integer updateUser(User user) {
        return userDao.updateUser(user);
    }

    @Override
    public Integer deleteId(Integer id) throws RuntimeException {

        return userDao.deleteId(id);
    }
}
